public class Strings
{
   /**
      Gets the middle character or character pair from this string 
      when possible.
      @param str a string
      @return the middle character (if the string length is odd) or
      the middle two characters (if it is even), or the empty string if str is
      empty.
   */
   public static String getMiddle(String str)
   {
      char arr[] = str.toCharArray();
      if(arr.length == 0)
      {
         return "";
      }
      if(arr.length % 2 == 1)
      {
         return arr[arr.length / 2] + "";
      }
      return arr[arr.length / 2 - 1] + "" + arr[arr.length / 2];
   }
}